<template>
  <div class="order-print app-container" id="print" ref="print">
    <div class="page-title">

      <div title="点击logo图标即可进行打印"><img src="../../assets/images/logo.png" style="width:15%" v-print="printObj"/></div>
      <div><h3>[ 订 单 详 情 ]</h3>
      <p>No.{{orderDetails.id_public_goods_order_record}}</p></div>
      
      <!-- <el-button type="primary" size="small" v-print="printObj">打印</el-button> -->
    </div>
    <div class="order-ino">
      <el-row :gutter="20">
        <el-col :span="8"><span>下单用户:</span><span class="col-value">{{ orderDetails.receive_name }}</span></el-col>
        <el-col :span="8"><span>消费门店:</span><span class="col-value">{{ public_agent_info.agent_name }}</span></el-col>
        <el-col :span="8"><span>送货方式:</span><span class="col-value">{{ orderDetails.type_of_shipment === 1 ? '用户自提' : '送货上门' }}</span></el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8"><span>用户ID:</span><span class="col-value">{{ orderDetails.buyer_id }}</span></el-col>
        <el-col :span="8"><span>客户电话:</span><span class="col-value">{{ orderDetails.phone_user }}</span></el-col>
        <el-col :span="8"><span>订单状态:</span><span class="col-value">{{ orderState[orderDetails.ship_state] }}</span></el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8"><span>订单总价:</span><span class="col-value">{{ Number(orderDetails.all_price_4_shop_retail).toFixed(2) }}</span></el-col>
        <el-col :span="8"><span>运费:</span><span class="col-value">{{ Number(orderDetails.ship_money).toFixed(2) }}</span></el-col>
        <el-col :span="8"><span>支付金额:</span><span class="col-value">{{ Number(orderDetails.ways_of_payment).toString().charAt(0) === '4' ? '微信支付(' + (Number(orderDetails.pay_by_online).toFixed(2)) + ')' : (Number(orderDetails.ways_of_payment).toString().charAt(0) === '3' ? '支付宝支付(' + (Number(orderDetails.pay_by_online).toFixed(2)) + ')' : '线下支付(' + (Number(orderDetails.pay_by_online).toFixed(2)) + ')') }}</span></el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8"><span>下单时间:</span><span class="col-value">{{ orderDetails.time_order }}</span></el-col>
        <el-col :span="12"><span>客户住址:</span><span class="col-value">{{ orderDetails.receive_place }}</span></el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="8"><span>要求时间:</span><span class="col-value">{{ orderDetails.time_require || '-' }}</span></el-col>
        <el-col :span="14"><span>订单备注:</span><span class="col-value">{{ orderDetails.order_remark || '-' }}</span></el-col>
      </el-row>
    </div>
    <div class="goods-info">
      <table>
        <thead>
          <td>序号</td>
          <td>商品/服务</td>
          <td>一级/二级类</td>
          <td>零售规格</td>
          <td class="current">源价/供价/零售价</td>
          <td>数量</td>
        </thead>
        <tbody>
          <tr v-for="(item, index) of orderGoods" :key="index">
            <td class="tIndex">{{index+1}}</td>
            <td>{{ item.goods_name }}</td>
            <td>{{ item.type_name }} / {{ item.child_name }}</td>
            <td>{{ item.sales_describe || '-' }}</td>
            <td class="current">{{ item.price_4_supply_buy }}/{{ item.price_4_shop_buy }}/{{ item.price_4_shop_retail }}</td>
            <td>{{ item.order_number }}</td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
import {orderDetail} from "@/api/order";

export default {
  name: "OrderPrint",
  data() {
    return {
      printObj: {
        id: "print",
        popTitle: "订单打印",
        extraHead: '<meta http-equiv="Content-Language" content="zh-cn"/>',
      },
      listLoading: true,
      orderDetails: {},
      public_agent_info: {},
      orderGoods: [],
      detailQuery: {
        invoke_method: 'details_4_order',
        id_public_goods_order_record: null
      },
      orderState: {
        0: '已发货',
        1: '已支付',
        3: '配货中',
        4: '已签收',
        5: '已取消',
        8: '支付失败',
        9: '退货中',
        10: '已退款'
      }
    }
  },
  mounted() {
    this.getDetails()
  },
  methods: {
    getDetails() {
      this.detailQuery.id_public_goods_order_record = this.$route.query.order_id
      orderDetail(this.Qs.stringify(this.detailQuery)).then(response => {
        this.orderGoods = response.public_goods_order_detail_list
        this.orderDetails = response.public_goods_order_record
        this.public_agent_info = response.public_agent_info
        setTimeout(() => {
          this.listLoading = false
        }, 0.5 * 1000)
      })
    },
  }
}
</script>
<style lang="scss" scoped>
.page-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 36px;
}
.el-row {
  font-size: 14px;
  color: #999999;
  margin-bottom: 16px;
  .el-col.current {
    opacity: 0;
  }
  .col-value {
    font-size: 16px;
    color: #222222;
    margin-left: 12px;
  }
}

table {
  font-family: Arial, sans-serif;
  font-size: 14px;
  background-color: #f0f2f5;
  border-collapse: collapse;
  color: #454545;
  table-layout: auto;
  width: 100%;
  text-align: center;
  border-bottom-width: 1px;
  border-bottom-style: solid;
  border-bottom-color: #dadcde;
  thead {
    border-top-width: 1px;
    border-top-style: solid;
    border-top-color: #dadcde;
    line-height: 40px;
    font-weight: bold;
    color: #454c70;
  }
  tr {
    border-top-width: 1px;
    border-top-style: solid;
    border-top-color: #dadcde;
    line-height: 23px;
  }
  td{
    padding: 5px 10px;
    font-size: 12px;
    font-family: Verdana;
    width: 100px;
    word-break: break-all; // 元素换行
    &.current {
      width: 120px;
    };
    &.tIndex {
      width:5px;
    }
  }
  // 斑马纹效果stripe
  tr:nth-child(even) {
    background: #F5F7F9;
  }
  tr:nth-child(odd) {
    background: #FFF;
  }
}
</style>
